package com.qf.ssm.controller;

import com.qf.ssm.dto.R;
import com.qf.ssm.pojo.Role;
import com.qf.ssm.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roles")
public class RoleController {

    private RoleService roleService;

    @Autowired
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }

    @PostMapping("/role")
    public R addRole(@RequestBody Role role){
        roleService.addRole(role);
        return R.setOK();
    }

    @PutMapping("/role")
    public R update(@RequestBody Role role){
        roleService.updateRole(role);
        return R.setOK();
    }

    @GetMapping("/roles")
    public R findRoleByUserId(Long uid){
        List<Role> roleList = roleService.findRoleByUserId(uid);
        return R.setOK(roleList);
    }
}
